package com.mes.web.controller.yzl;


import com.mes.entity.hpf.SalePlanDetail;
import com.mes.entity.yzl.Condition;
import com.mes.entity.yzl.ListBack;
import com.mes.entity.yzlExtend.ExtendProductor;
import com.mes.service.yzl.SalechartService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/yzl")
public class SalechartController {

    @Resource
    private SalechartService salechartService;

    @RequestMapping("/saleChartList")
    public @ResponseBody ListBack saleChartList(Condition condition){
        ListBack listBack = new ListBack();
        List<SalePlanDetail> productors = new ArrayList<>();

        if(condition.getRecent()==0){//
            if(condition.getBeginDate() == "" || condition.getBeginDate() == null){
                condition.setBeginDate("1970-1-1");
            }
            if(condition.getEndDate() == "" || condition.getEndDate() == null){
                condition.setEndDate("2200-12-30");
            }
        }else{//选择最近时间
            condition.setRecent(condition.getRecent());
        }

        if(condition.getCustomerName() == null){
            condition.setCustomerName("");
        }else{
            if(condition.getCustomerName().equals("所有客户")){
                condition.setCustomerName("");
            }
        }



        //条件查询总数
        int count = salechartService.countSaleChart(condition);
        listBack.setTotal(count);
        //条件分页查询
        productors = salechartService.saleChartList(condition);
        listBack.setRows(productors);
        return listBack;
    }
    
    /***
     * 侯鹏飞
     * 退货对比信息
     * @param condition
     * @return
     */
    @RequestMapping("/saleChartReturnList")
    public @ResponseBody ListBack saleChartReturnList(Condition condition){
    	ListBack listBack = new ListBack();
    	List<ExtendProductor> productors = new ArrayList<>();
    	
    	if(condition.getRecent()==0){//
    		if(condition.getBeginDate() == "" || condition.getBeginDate() == null){
    			condition.setBeginDate("1970-1-1");
    		}
    		if(condition.getEndDate() == "" || condition.getEndDate() == null){
    			condition.setEndDate("2200-12-30");
    		}
    	}else{//选择最近时间
    		condition.setRecent(condition.getRecent());
    	}
    	
    	if(condition.getCustomerName() == null){
    		condition.setCustomerName("");
    	}else{
    		if(condition.getCustomerName().equals("所有客户")){
    			condition.setCustomerName("");
    		}
    	}
    	
    	
    	
    	//条件查询总数
    	int count = salechartService.countSaleChartReturn(condition);
    	listBack.setTotal(count);
    	//条件分页查询
    	productors = salechartService.saleChartReturnList(condition);
    	listBack.setRows(productors);
    	return listBack;
    }
    
    /***
     * 侯鹏飞
     * 查询计划与实际对比图形报表数据
     * @param condition
     * @return
     */
    @RequestMapping("/saleChartAllList")
    public @ResponseBody ListBack saleChartAllList(){
    	ListBack listBack = new ListBack();
    	List<SalePlanDetail> productors = new ArrayList<>();
    	productors = salechartService.saleChartAllList();
    	listBack.setRows(productors);
    	return listBack;
    }
    
    /***
     * 侯鹏飞
     * 查询退货图形报表数据
     * @param condition
     * @return
     */
    @RequestMapping("/saleChartReturnAllList")
    public @ResponseBody ListBack saleChartReturnAllList(){
    	ListBack listBack = new ListBack();
    	List<ExtendProductor> productors = new ArrayList<>();
    	productors = salechartService.saleChartReturnAllList();
    	listBack.setRows(productors);
    	return listBack;
    }

}
